package de.obs.mvl.xml;

import javax.swing.JFileChooser;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.*;

public class Xml2html {
        public static void main(String[] args)
    throws TransformerException, 
    TransformerConfigurationException, 
           FileNotFoundException, IOException
  {  
        //User Chooses a Path and Name for the html Output File
        JFileChooser fc = new JFileChooser();
        fc.setDialogType(JFileChooser.SAVE_DIALOG);

        int state = fc.showSaveDialog(null);
        String htmlPath = "default.html";
        if (state == JFileChooser.APPROVE_OPTION)
        {
        	htmlPath = fc.getSelectedFile().getPath();
        	if(!htmlPath.endsWith(".html")){
        		htmlPath = htmlPath + ".html";
        	}
            //arg0=data.xml arg1=output.html
            TransformerFactory tFactory = 
            TransformerFactory.newInstance();
            Transformer transformer = 
            tFactory.newTransformer(
            new StreamSource("style_xml_sheet.xsl"));
            //transformer.transform(new StreamSource(args[0]), new StreamResult(new FileOutputStream(args[1])));
            transformer.transform(new StreamSource("data_new2.xml"), new StreamResult(new FileOutputStream(htmlPath)));
            System.out.println
            ("** The output is written in " + htmlPath + " **");
        	
        }else{
            System.out.println
            ("** The output is NOT written because no directory was selected **");
  
        }

  }
}

